﻿using ACFaceAPI.yufan.Model;
using ACFaceAPI.yufan.Result;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace ACFaceAPI.yufan
{
    /// <summary>
    /// 返回数据扩展类
    /// </summary>
    public static class YuFanResultException
    {
        /// <summary>
        /// 获取错误说明
        /// </summary>
        public static string GetErrorMsg(this YuFanResult result)
        {
            if (result.code == "") { return "未检测到错误码"; }
            if(YuFanCode.Codes.TryGetValue(result.code,out string codeMsg))
            {
                return codeMsg;
            }
            else
            {
                return "未检测到错误码";
            }
        }

        public static YuFanResultConfig ToYuFanResultConfig(this YuFanResult result)
        {
            YuFanResultConfig r = new YuFanResultConfig();
            r.msg = result?.msg;
            r.success = result.success;
            r.code = result?.code;
            r.result = result.result;
            r.data = JsonConvert.DeserializeObject<YuFanConfig>(result?.data.ToString());
            return r;
        }
    }
}
